
#include "Move.h"

//! Constructor
Move::Move(BoardPosition & begin, BoardPosition & last,
            Piece * movedPiece, Piece * takenPiece, Piece * changedPiece) {

   start = begin;
   end = last;
   moved = movedPiece;
   taken = takenPiece;
   changed = changedPiece;
}

Move & Move::operator=(Move & other){
   moved = other.moved;
   taken = other.taken;
   start = other.start;
   end = other.end;
   changed = other.changed;

   return *this;
}

std::ostream & Move::Save(std::ostream & os) {

   os << "<move>" << std::endl;

   moved->Save(os, start.GetRow(), start.GetCol());

   changed == NULL ? moved->Save(os, end.GetRow(), end.GetCol()) :
                 changed->Save(os, end.GetRow(), end.GetCol());
   if (taken != NULL)
      taken->Save(os, end.GetRow(), end.GetCol());

   os << "</move>" << std::endl;

   return os;
}
